//一致字符串
const allowed='abd'
const words=['ab','bd','aab','aabbcc']

function fun(allowed:string,words:string[]){
    let n=0
    for(let i=0;i<words.length;i++){
        let nom=0
        for(let k of words[i]){
            if(allowed.indexOf(k)!=-1){
                if(allowed.indexOf(k)!=-1){
                    nom++
                }else{
                    nom=0
                    break
                }
            }
            nom?n++:n
        }
        return n
    }
}
console.log(fun(allowed,words));





//买卖股票最佳时期
let Max=function(price:number[]){
    let total=0;
    for(let i=0;i<price.length-1;i++){
        total+=Math.max(price[i+1]-price[i],0)
    }
    return total
}
console.log(Max([6,1,5,3,6,4]));





//只出现一次的元素
let brr=[4,1,2,1,2]
let Fomer=function(arr:number[]){
    let n=0;
    for(let i=0;i<arr.length;i++){
        n^=arr[i]
    }
    return n
}
console.log(Fomer(brr));





//把2维转一维
function flat(arr:Array<Array<number>|number>):Array<number>{
    let newArr:Array<number>=[]
    arr.forEach((item:Array<number>|number)=>{
        if(Array.isArray(item)){
            newArr.push(...flat(item))
        }else{
            newArr.push(item)
        }
    })
    return newArr
}
console.log(flat([[1,2,3],[4,5],6]));
